package com.langsin.crmpro.utils;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;

public class CreateSetMethod {

	public static void creanteSetMethod(String url, String objName)
			throws Exception {
		// 得到要生成set方法的java类中所有代码
		BufferedReader br = new BufferedReader(new InputStreamReader(
				new FileInputStream(url)));
		// "D:\\eclipse_work\\CrmPro\\src\\com\\langsin\\crmpro\\model\\User.java"
		// 通过正则表达式和一系列的替换达到生成set方法的需求
		String s = "";
		while ((s = br.readLine()) != null) {
			s = s.trim();
			if (s.matches("private [\\w]+ [\\w]+;")) {
				String tmpStr = "";
				s = s.substring(s.lastIndexOf(" ") + 1, s.length() - 1);
				tmpStr = s;
				StringBuilder strbu = new StringBuilder(s);
				strbu.setCharAt(0,Character.toTitleCase(s.charAt(0)));
				s = strbu.toString();
				s = objName + ".set" + s + "(this." + tmpStr + ");";
				System.out.println(s);
				
			}

		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		CreateSetMethod
				.creanteSetMethod(
						"D:\\eclipse_work\\CrmPro\\src\\com\\langsin\\crmpro\\model\\User.java",
						"u");
	}

}
